home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_091 / samples / demos / actdemo.adl next >
Text File  |  1992-05-06  |  12KB  |  598 lines

  1. INCLUDE "standard.adl";        { Include the standard package }
  2.  
  3.  
  4. { The following are Object properties }
  5.  
  6. BROKEN  =  1;        { Is the robot damaged? }
  7. TOLD    =  2;        { Have I told the robot something? }
  8. BSTATE    = 17;        { State of the button }
  9.     B_OFF    =  0;    { Button is off }
  10.     B_FLASH    =  1;    { Button is flashing }
  11.     B_LIT    =  2;    { Button is lit }
  12.  
  13.  
  14. { Global variables }
  15.  
  16. VAR
  17.     RobSave[ 6 ],    { Saved sentence for the robot }
  18.     Score;        { Current score }
  19.  
  20.  
  21. { Utility routines }
  22.  
  23. ROUTINE
  24.     NoGo,     Sayer,    Myself,    Lifter,
  25.     DoorCk,    TrapCk,    RobMov, BlueCk,
  26.     Header,    Die,    Skore,    RobEntr,
  27.     HatchSD;
  28.  
  29.  
  30. { Locations in the dungeon }
  31.  
  32. NOUN
  33.     Redrm,        Bluerm,
  34.     Greenrm,    Cellar,
  35.     Endrm;
  36.  
  37.  
  38. { Immovable objects }
  39.  
  40. NOUN
  41.     button( Bluerm ),
  42.     door( Cellar ),
  43.     hatch( Bluerm );
  44.  
  45.  
  46. { Objects which may become actors }
  47.  
  48. NOUN
  49.     me( Redrm ),
  50.     robot( Greenrm );
  51.  
  52. me(NOTAKE) = TRUE;
  53.  
  54.  
  55. { Room descriptions }
  56.  
  57. Redrm( LDESC ) =
  58.     ($say
  59. "You are in a large room which is illuminated by a bright
  60. red glow.  Exits lie to the east and south.\n"
  61.     )
  62. ;
  63. Redrm( SDESC ) = ($return (Header "Red room" %0));
  64. Redrm( LIGHT ) = TRUE;
  65.  
  66.  
  67. Greenrm( LDESC ) =
  68.     ($say
  69. "You are in a smallish room which is illuminated by a pleasant
  70. green glow.  The only exit is to the west.\n"
  71.     )
  72. ;
  73. Greenrm( SDESC ) = ($return (Header "Green room" %0));
  74. Greenrm( LIGHT ) = TRUE;
  75.  
  76.  
  77. Bluerm( LDESC ) =
  78.     ($say
  79. "You are in a tiny room which is barely illuminated by a
  80. dim blue glow.  There is an exit to the north,"
  81.     )
  82.     (IF ($eq ($prop button BSTATE) B_LIT) THEN
  83.         ($say
  84. " and most of the floor has tilted up to reveal a hatch leading
  85. down into blackness.  A button on the wall is glowing brightly."
  86.         )
  87.      ELSE
  88.         ($say " and you seem to make out something on the floor.")
  89.         (IF ($prop button BSTATE) THEN
  90.             ($say "  A button on the wall is flashing urgently.")
  91.          ELSE
  92.             ($say "  There is a button on the wall.")
  93.         )
  94.     )
  95.     ($say
  96. "  Above the button is a sign that reads:\n\n"
  97. "        DANGER!\n\n"
  98. "         HIGH VOLTAGE!\n\n"
  99.     )
  100. ;
  101. Bluerm( SDESC ) =
  102.     (IF %0 THEN ($return "Blue room"))
  103.     ($say "Blue room.\n")
  104. ;
  105. Bluerm( LIGHT ) = TRUE;
  106.  
  107.  
  108. Cellar( LDESC ) =
  109.     ($say
  110. "You are in the cellar.  Far above you can be seen a dim
  111. blue light."
  112.     )
  113.     (IF ($prop door OPENED) THEN
  114.         ($say
  115. "  An open door leads to the north.\n"
  116.         )
  117.      ELSE
  118.         ($say
  119. "  You can barely see the outline of a door to the north.\n"
  120.         )
  121.     )
  122. ;
  123. Cellar( SDESC ) =
  124.     ($return (Header "Cellar" %0))
  125. ;
  126. Cellar( LIGHT ) = TRUE;
  127.  
  128.  
  129. Endrm( LDESC ) =
  130.     ($say
  131. "You exit from the dark cellar into a land filled with singing birds,
  132. blooming flowers, flowing streams, and bright blue skies.  In other words,
  133. you have finished this game!\n"
  134.     )
  135.     ($setg Score ($plus @Score 25))
  136.     (Skore)
  137.     ($spec 3)
  138. ;
  139. Endrm( LIGHT ) = TRUE;
  140.  
  141.  
  142. { Verbs }
  143.  
  144. VERB
  145.     score,
  146.     push,
  147.     shout;
  148.  
  149. tell = TELLER;
  150. say = tell;
  151. press = push;
  152. feel = touch;
  153. yell = shout;
  154.  
  155.  
  156. { Verb routines }
  157.  
  158. tell( PREACT ) =
  159.     (IF ($ne @Iobj robot) THEN
  160.         { The only logical thing to talk to is the robot }
  161.         (Sayer
  162. "Talking to yourself is said to be a sign of impending insanity"
  163.         )
  164.      ELSEIF ($ge @Dobj 0) THEN
  165.         { You must say strings }
  166.         (Sayer
  167. "You must put what you want to say in quotes"
  168.         )
  169.      ELSEIF ($ne ($loc robot) ($loc me)) THEN
  170.         { The robot must be in the same place as the player }
  171.         (IF (Myself) THEN
  172.             ($say "You don't see the robot here.\n")
  173.         )
  174.      ELSE
  175.         { Everything is OK.  Add 25 points to the score }
  176.         (IF ($not ($prop robot TOLD)) THEN
  177.             ($setg Score ($plus @Score 25))
  178.             ($setp robot TOLD TRUE)
  179.         )
  180.         ($exit 0)
  181.     )
  182.     ($exit 1)
  183. ;
  184. tell( ACTION ) =
  185.     { Tell the player that we heard him }
  186.     ($say "\"Sure thing, Boss.\"\n")
  187.  
  188.     { Delete the old action }
  189.     ($delact robot)
  190.  
  191.     { Add the new action - a non-interactive actor }
  192.     ($actor robot @Dobj FALSE)
  193. ;
  194.  
  195.  
  196. shout( PREACT ) =
  197.     (IF    ($and @Iobj ($ne @Iobj robot)) THEN
  198.         { Shouting at things other than the robot }
  199.         ($say "AAARRRGGGHHH!\n")
  200.      ELSEIF    ($ge @Dobj 0) THEN
  201.         { Shouting things other than strings }
  202.         ($say "EEEYYYAAAHHH!\n")
  203.      ELSEIF    ($prop robot BROKEN) THEN
  204.         ($say "There is no response.\n")
  205.      ELSE
  206.         { Shouting at the robot - same as telling the robot }
  207.         (IF ($not ($prop robot TOLD)) THEN
  208.             ($setg Score ($plus @Score 25))
  209.             ($setp robot TOLD TRUE)
  210.         )
  211.         ($exit 0)
  212.     )
  213.     ($exit 1)
  214. ;
  215. shout( ACTION ) =
  216.     { Tell the player we heard him }
  217.     (IF ($ne ($loc robot) ($loc me)) THEN
  218.         ($say "In the distance you hear the words, ")
  219.     )
  220.     ($say "\"Sure thing, Boss\"\n")
  221.  
  222.     { Delete the old robot action }
  223.     ($delact robot)
  224.  
  225.     { Add the new robot action }
  226.     ($actor robot @Dobj FALSE)
  227. ;
  228.  
  229.  
  230. push( PREACT ) =
  231.     { Expect a plain direct object }
  232.     (Expect ($or ONE_OBJ PLAIN_OBJ) NO_OBJ)
  233.     (CheckAvail)
  234. ;
  235. push( ACTION ) =
  236.     (Sayer "That doesn't seem to do anything")
  237.     ($exit 1)
  238. ;
  239.  
  240.  
  241. score(PREACT) =
  242.     { Score can accept no objects }
  243.     (Expect NO_OBJ NO_OBJ)
  244.     (Skore)
  245.     ($exit 1)
  246. ;
  247.  
  248.  
  249. { Object properties }
  250.  
  251. button( SDESC ) =
  252.     (IF ($eq ($prop button BSTATE) B_OFF) THEN
  253.         ($say "a button")
  254.      ELSEIF ($eq ($prop button BSTATE) B_FLASH) THEN
  255.         ($say "an urgently flashing button")
  256.      ELSE
  257.         ($say "a brightly lit button")
  258.     )
  259. ;
  260. button( ACTION ) =
  261.     (IF ($and    (Myself)
  262.             ($or    ($eq @Verb push)
  263.                 ($eq @Verb take)
  264.                 ($eq @Verb touch)
  265.             )
  266.         )
  267.      THEN
  268.         { The player tried to do something with the button }
  269.         ($say
  270. "As you reach for the button, a 10,000,000 volt bolt of lightning
  271. arcs toward your finger, disintegrating you upon impact.\n"
  272.         )
  273.         (Die)
  274.      ELSEIF ($and ($eq @Verb push) ($eq ($prop button BSTATE) B_OFF)) THEN
  275.         { The robot pushed the button }
  276.         ($setp button BSTATE B_FLASH)
  277.         ($setg Score ($plus @Score 50))
  278.         ($sfus me Lifter 4)
  279.         ($exit 1)
  280.      ELSEIF ($eq @Verb take) THEN
  281.         { Can't take the button }
  282.         ($setg Skip TRUE)
  283.     )
  284. ;
  285.  
  286.  
  287. SimpleRobot = "I am just a simple robot";
  288. robot( LDESC ) = ($say "There is a robot here.\n");
  289. robot( SDESC ) = ($say "a robot");
  290. robot( ACTION ) =
  291.     (IF (Myself) THEN
  292.         { I'm doing something with the robot }
  293.         (IF ($eq @Verb tell) THEN
  294.             (IF ($prop robot BROKEN) THEN
  295.                 ($say "There is no response.\n")
  296.                 ($exit 1)
  297.                 )
  298.          ELSEIF ($eq @Verb take) THEN
  299.             ($say "The robot weighs at least 500 pounds!\n")
  300.             ($exit 1)
  301.         )
  302.      ELSEIF ($eq ($phase) 2) THEN
  303.         { This is being called as the Actor ACTION }
  304.         (ActAction)
  305.         (IF ($and    ($ne @Verb push)
  306.                 ($ne @Verb go)
  307.                 ($ne @Verb wait)
  308.                 ($ne @Verb take)
  309.                 ($or ($lt @Verb north) ($gt @Verb down)))
  310.          THEN
  311.             { The robot has a VERY simple vocabulary }
  312.             (Sayer SimpleRobot)
  313.             ($delact robot)
  314.             ($exit 1)
  315.         )
  316.      ELSEIF ($eq @Verb take) THEN
  317.         { The robot is trying to take itself }
  318.         (Sayer "Mmmph!  Akkk!!  GGGGRR!!  No can do.  Sorry")
  319.         ($setg Skip TRUE)
  320.      ELSE
  321.         { The robot is doing something to itself }
  322.         (Sayer SimpleRobot)
  323.         ($delact robot)
  324.         ($exit 1)
  325.     )
  326. ;
  327. robot( SAVESENT ) = RobSave;
  328.  
  329.  
  330.  
  331. {    We break me( ACTION ) out into a named routine because
  332.     StdInit overwrites that property and we need to restore it    }
  333.  
  334. MeAct =
  335.     (IF ($eq ($phase) 2) THEN
  336.         { This is the Actor ACTION - call standard's actor action }
  337.         (ActAction)
  338.      ELSEIF ($eq @Verb take) THEN
  339.         (Sayer "I thought you would never ask")
  340.         ($setg Skip TRUE)
  341.     )
  342. ;
  343.  
  344.  
  345. {    We break hatch( SDESC ) out into a named routine because
  346.     the hatch isn't visible until after Lifter has executed        }
  347.  
  348. HatchSD = ($say "an open hatch");
  349. HatchMSG = "The hatch doesn't budge";
  350. hatch( ACTION ) =
  351.     (IF ($eq @Verb take) THEN
  352.         { Can't take the hatch }
  353.         (Sayer HatchMSG)
  354.         ($setg Skip TRUE)
  355.      ELSEIF ($or ($eq @Verb open) ($eq @Verb push)) THEN
  356.         { Can't open or push it, either }
  357.         (Sayer HatchMSG)
  358.         ($exit 1)
  359.     )
  360. ;
  361. hatch( OPENS ) = TRUE;
  362. hatch( NOTAKE ) = TRUE;
  363.  
  364.  
  365. door( SDESC ) = ($say "a door");
  366. door( ACTION ) =
  367.     (IF ($eq @Verb take) THEN
  368.         ($say "You can't take a door!\n")
  369.         ($setg Skip TRUE)
  370.     )
  371. ;
  372. door( OPENS ) = TRUE;
  373.  
  374.  
  375. {    Transition routines.  Note that RobMov is used in $miss.
  376.     This produces the 'The robot exits to the <direction>
  377.     messages.  The calls to RobEntr produce the messages like
  378.     'The robot enters from the <direction>.        }
  379.  
  380. Bluerm( ACTION ) =
  381.     ($miss RobMov NoGo NoGo NoGo NoGo TrapCk 0 0 0 0)
  382.     ($hit .ME Redrm 0 0 0 0 Cellar 0 0 0 0)
  383.     (RobEntr)
  384. ;
  385.  
  386.  
  387. Redrm( ACTION ) =
  388.     ($miss NoGo BlueCk RobMov NoGo NoGo NoGo 0 0 0 0)
  389.     ($hit .ME 0 Bluerm Greenrm 0 0 0 0 0 0 0)
  390.     (RobEntr)
  391. ;
  392.  
  393.  
  394. Greenrm( ACTION ) =
  395.     ($miss NoGo NoGo NoGo RobMov NoGo NoGo 0 0 0 0)
  396.     ($hit .ME 0 0 0 Redrm 0 0 0 0 0 0)
  397.     (RobEntr)
  398. ;
  399.  
  400.  
  401. Cellar( ACTION ) =
  402.     ($miss DoorCk NoGo NoGo NoGo BlueCk NoGo 0 0 0 0)
  403.     ($hit .ME Endrm 0 0 0 Bluerm 0 0 0 0 0)
  404.     (RobEntr)
  405. ;
  406.  
  407.  
  408. { Routines }
  409.  
  410. { (Myself) - returns 1 if "me" is the current actor; 0 otherwise }
  411. Myself =
  412.     ($return ($eq .ME me))
  413. ;
  414.  
  415.  
  416. {    (Sayer str) - Says a string with appropriate quoting, depending
  417.     on whether the robot or the player is doing the saying.        }
  418. Sayer =
  419.     (IF (Myself) THEN
  420.         ($say %1 ".\n")
  421.      ELSEIF ($eq ($loc robot) ($loc me)) THEN
  422.         ($say "\"" %1 ", Boss.\"\n")
  423.      ELSE
  424.         ($say "You hear a muffled voice in the distance.\n")
  425.     )
  426. ;
  427.  
  428.  
  429. {    (NoGo) - "You can't go that way"    }
  430. NoGo =
  431.     (Sayer "You can't go that way")
  432.     ($exit 1)
  433. ;
  434.  
  435.  
  436. {    (Header str arg0) - To accomplish the printing of header lines,
  437.     each location SDESC need to return a string if a parameter is
  438.     passed to it.  By doing ($return (Header <sdesc> %0)), we can
  439.     centralize the saying/returning decision.    }
  440. Header =
  441.     (IF ($not %2) THEN
  442.         ($say %1 ".\n")
  443.     )
  444.     ($return %1)
  445. ;
  446.  
  447.  
  448. RobMov =
  449.     (IF ($and ($not (Myself)) ($eq ($loc robot) ($loc me))) THEN
  450.         ($say
  451.             "The robot exits to the "
  452.             (IF ($eq @Verb e) THEN
  453.                 ($val "east")
  454.              ELSEIF ($eq @Verb w) THEN
  455.                 ($val "west")
  456.              ELSEIF ($eq @Verb s) THEN
  457.                 ($val "south")
  458.              { The robot can't be seen leaving to the north }
  459.             )
  460.             ".\n"
  461.         )
  462.     )
  463. ;
  464.  
  465.  
  466. RobEntr =
  467.     (IF ($and ($not (Myself)) ($eq ($loc robot ) ($loc me))) THEN
  468.         ($say
  469.             (IF ($eq @Verb north) THEN
  470.                 ($val "The robot enters from the south.\n")
  471.              ELSEIF ($eq @Verb east) THEN
  472.                 ($val "The robot enters from the west.\n")
  473.              ELSEIF ($eq @Verb west) THEN
  474.                 ($val "The robot enters from the east.\n")
  475.              { The robot can't enter from the north in
  476.                this scenario }
  477.             )
  478.         )
  479.     )
  480. ;
  481.  
  482.  
  483. DoorCk =
  484.     (IF ($not ($prop door OPENED)) THEN
  485.         ($say "The door seems to be closed.\n")
  486.         ($exit 1)
  487.     )
  488. ;
  489.  
  490.  
  491. TrapCk =
  492.     (IF ($ne ($prop button BSTATE) B_LIT) THEN
  493.         (NoGo)
  494.     )
  495. ;
  496.  
  497.  
  498. {    (BlueCk) - make sure that only one actor is in the blue room
  499.     at one time.    }
  500. BlueCk =
  501.     (IF ($or ($eq ($loc me) Bluerm) ($eq ($loc robot) Bluerm)) THEN
  502.         (IF (Myself) THEN
  503.             ($say
  504. "The room is too small for both you and the robot to fit.\n"
  505.             )
  506.         )
  507.         ($exit 1)
  508.      ELSEIF ($and ($not (Myself)) ($eq ($prop button BSTATE) B_LIT)) THEN
  509.         (RobMov)
  510.         ($say "You hear a loud CRASH! in the distance.\n")
  511.         ($setg Score ($minus @Score 10))
  512.         ($setp robot BROKEN TRUE)
  513.         ($move robot Bluerm)
  514.         ($delact robot)
  515.         ($exit 1)
  516.     )
  517.     (RobMov)
  518. ;
  519.  
  520.  
  521. {    (Die) - kill off the player    }
  522. Die =
  523.     ($setg Score ($minus @Score 50))
  524.     (Skore)
  525.     ($say "Do you wish to restart the game? ")
  526.     (IF ($yorn) THEN
  527.         ($spec 2)
  528.      ELSE
  529.         ($spec 3)
  530.     )
  531. ;
  532.  
  533.  
  534. {    (Lifter) - Lift the hatch, possibly killing the robot or
  535.     the player    }
  536. Lifter =
  537.     (IF ($eq ($loc me) Bluerm) THEN
  538.         ($say
  539. "All of a sudden, the floor lifts up, and you are crushed between it
  540. and the wall!  "
  541.         )
  542.         (Die)
  543.      ELSE
  544.         ($say "In the distance, you hear a loud CRASH!\n")
  545.         (IF ($eq ($loc robot) Bluerm) THEN
  546.             ($setg Score ($minus @Score 10))
  547.             ($setp robot BROKEN TRUE)
  548.             ($delact robot)
  549.         )
  550.     )
  551.     ($setp hatch SDESC HatchSD)
  552.     ($setp button BSTATE B_LIT)
  553.     ($setp Bluerm SEEN FALSE)
  554. ;
  555.  
  556.  
  557. {    Prompt - print the status line and a prompt    }
  558. PROMPT =
  559.     ($spec 9 (($sdesc ($loc .ME)) 1) @Score ($turns))
  560.     ($say "> ")
  561. ;
  562.  
  563.  
  564. {    Increment - increment the turn counter    }
  565. INCREMENT =
  566.     (IF (Myself) THEN
  567.         { We only want to increment once per turn }
  568.         ($incturn)
  569.      ELSE
  570.         { We don't want Looker executing for the robot }
  571.         ($exit 0)
  572.     )
  573. ;
  574.  
  575.  
  576. {    (Skore) - print out the current score.    }
  577. Skore =
  578.     ($say    "You have scored " ($str @Score)
  579.         " out of a possible 100 in " ($str ($turns)) " moves.\n")
  580. ;
  581.  
  582.  
  583. {    Dwimming routines    }
  584. DWIMI = (Dwimmer %1);
  585. DWIMD = (Dwimmer %1);
  586.  
  587. START =
  588.     ($spec MARGIN 69)    { Set the screen to 69 wide }
  589.     ($sdem INCREMENT)    { Turn counter increment }
  590.     (StdInit me)        { Initialize standard }
  591.     ($setp me ACTION MeAct)    { Restore me( ACTION ) }
  592.     ($setv n s e w u d 0 0 0 0)    { Use our own transition vector }
  593.     ($prompt PROMPT)    { and our own prompter }
  594.     ($setg Indent TRUE)    { Indent the object descriptions }
  595. ;
  596.  
  597. {*** EOF actdemo.adl ***}
  598.